package apis.amapv2.com.searchview;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

/**
 * https://blog.csdn.net/Chay_Chan/article/details/76511028
 *
 */
public class MainActivity extends AppCompatActivity {

    private ListView mLv;
    private Context mContext;//上下文
    private List<String> mData = new ArrayList<>();//存储ListView的数据


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        initParamsAndValus();

        initView();
    }

    private void initParamsAndValus() {
        mContext = this;
        mData.add("SearchView的通常使用");
    }

    private void initView() {
        mLv = findViewById(R.id.lv);
        mLv.setAdapter(new ArrayAdapter<>(mContext,android.R.layout.simple_list_item_1,mData));
        mLv.setOnItemClickListener(mOnItemClickListener);
    }

    /**
     * ListView的点击每一个条目的监听
     */
    AdapterView.OnItemClickListener mOnItemClickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0){
                startActivity(new Intent(mContext,Test0Activity.class));
            }
        }
    };
}
